-
Notifications
You must be signed in to change notification settings - Fork 8.9k
test: fix JUnit test method access modifiers and annotations #7635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there similar cases elsewhere?
If so, it would be good to address all of them in this PR.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #7635 +/- ##
=========================================
Coverage 67.28% 67.28%
- Complexity 992 994 +2
=========================================
Files 1323 1323
Lines 50155 50155
Branches 5928 5928
=========================================
+ Hits 33746 33748 +2
+ Misses 13488 13482 -6
- Partials 2921 2925 +4 🚀 New features to boost your workflow:
|
Thanks for your suggestion! I’ve checked and fixed all similar cases in the test classes. Could you please take another look when you get a chance? |
Please use JUnit5 instead of JUnit4. |
|
Done. Replaced all JUnit4 references with JUnit5. Please take another look when you get a chance. |
|
@YongGoose I've updated the PR based on your feedback. Could you please take another look when you have time? Thanks! |
|
The CI failure in the seata-config-zk module only occurs in the Java 8 build and is unrelated to my changes. The same tests pass successfully in Java 17 and Java 21, indicating a compatibility issue between ZooKeeper client and Java 8 in the CI environment—not a code problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test class is an integration test that relies on a real etcd service. Because it is marked with @Disable, CI will not be triggered. I think it is helpful to include a screenshot of the active triggering test in the description for reference.
|
Hi @YongGoose , |
|
@YongGoose Pls take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply spotless :)
Once you’ve fixed the Spotless issues, please ping me and I’ll give my approval.
| EtcdListener etcdListener = new EtcdListener(); | ||
| registryService.subscribe(CLUSTER_NAME, etcdListener); | ||
| // 3.delete instance,see if the listener can be notified | ||
| registryService.subscribe(DEFAULT_TX_GROUP, etcdListener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, was there any particular reason for using DEFAULT_TX_GROUP instead of CLUSTER_NAME?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! The subscribe() and lookup() methods expect a transaction service group, not an etcd cluster name.
The original code had mismatched key paths:
- Registration: registry-seata-<DEFAULT_TX_GROUP>/...
- Subscription: registry-seata-<CLUSTER_NAME>/...
Even though both values were "default", using DEFAULT_TX_GROUP is semantically correct and matches how Seata actually works - clients look up services by transaction group.
|
I've fixed the Spotless issues, plaese take a look : ) @YongGoose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR corrects JUnit test method access modifiers and annotation usage to ensure proper test execution. The changes address framework requirements where lifecycle methods and fields must be public rather than private, and remove incorrect @Test annotations from utility methods.
Key Changes:
- Changed
@BeforeEachand@AfterEachannotated methods from private to public visibility - Removed
@Testannotations from utility/helper methods that are not actual test cases - Refactored etcd3 test to use JUnit 5 lifecycle annotations instead of JUnit 4's
@Rule
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/src/test/java/org/apache/seata/at/oracle/SupportOracleDataTypeTest.java | Removed @Test annotation from testTypeSql utility method |
| test/src/test/java/org/apache/seata/at/ATModeSupportDataBaseDataTypeTest.java | Removed @Test annotation from helper method and fixed method call bugs |
| server/src/test/java/org/apache/seata/server/ParameterParserTest.java | Changed @BeforeEach method from private to public |
| rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/BaseH2Test.java | Changed @BeforeEach method from private to public |
| discovery/seata-discovery-etcd3/src/test/java/org/apache/seata/discovery/registry/etcd3/EtcdRegistryServiceImplTest.java | Migrated from JUnit 4 @Rule to JUnit 5 lifecycle methods with proper setup/teardown |
| discovery/seata-discovery-etcd3/pom.xml | Added mockito-core test dependency |
| changes/zh-cn/2.x.md | Added changelog entry in Chinese |
| changes/en-us/2.x.md | Added changelog entry in English |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
I think this pr can be merged now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ⅰ. Describe what this PR did
This PR corrects JUnit test method access modifiers and annotation usage:
@BeforeEach/@AfterEachmethod visibility in JUnit 5 tests (private → public)@Rulefield access modifier in JUnit 4 tests (private → public)@Testannotation from utility methodsThese changes ensure proper JUnit framework functionality and test execution.
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews